﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Com.CMS263.PO;

namespace Com.CMS263.DAO
{
    public  class ProdAttributeDAO:BaseService
    {
        public IList<ProdAttribute> FindAll()
        {
            string hql = "from ProdAttribute order by Id desc";
            return FindList<ProdAttribute>(hql, null, null, null);
        }
        public IList<ProdAttribute> GetAllByType(int prodtypeid)
        {
            string hql = "from ProdAttribute where ProdTypeId=" + prodtypeid;
            return FindList<ProdAttribute>(hql, null, null, null);
        }

        #region 给据id查询实体
        /// <summary>
        /// 给据id查询实体
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ProdAttribute GetPrById(int id)
        {
            try
            {
                string hql = "from ProdAttribute where Id=" + id;
                return DBHelper.ExecuteHQL(hql).List<ProdAttribute>().First();
            }
            catch
            {
                return null;
            }
        }
        #endregion

        #region 根据ProdTypeId查询个数
        /// <summary>
        /// 根据ProdTypeId查询个数
        /// </summary>
        /// <param name="ptid"></param>
        /// <returns></returns>
        public int GetCountByProdTypeId(int ptid)
        {
            
            string hql = "select count(*) from ProdAttribute where ProdTypeId="+ptid;
            return Convert.ToInt32(GetValue(hql));
        }
        #endregion

        #region 根据ProdTypeId删除相关信息
        /// <summary>
        /// 根据ProdTypeId删除相关信息
        /// </summary>
        /// <param name="ptid"></param>
        /// <returns></returns>
        public int DelByProdTypeId(int ptid)
        {
            string hql = "delete from ProdAttribute where ProdTypeId="+ptid;
            return DBHelper.ExecuteHQL(hql).ExecuteUpdate();
        }
        #endregion
    }
}
